#include <stdio.h>

void swap(int* x, int* y) {
	int temp;
	temp = *y;
	*y = *x;
	*x = temp;
}

int bubbleSort(int arr[], int n) {
	int i;
	if (n == 1) {
		return 0;	
	}

	for (int i = 0; i < n-1; ++i) {
		if (arr[i] > arr[i+1]) {
			swap(&arr[i], &arr[i+1]);	
		}
	}
	bubbleSort(arr, n - 1);
}


/**
* bubble(int arr[], n);
* bubble(int arr[], n - 1);
* bubble(int arr[], n - 2);
* ...
* bubble(int arr[], 1);
*/

void print(int arr[], int n) {
	int i;
	for (i = 0; i < n; ++i) {
		printf("%d ", arr[i]);
	}
	printf("\n");
}

int main() {
	int a[5] = {2, 4, 3, 5, 1};
	printf("Before: ");
	print(a, 5);
	
	bubbleSort(a, 5);

	printf("After: ");
	print(a, 5);

	return 0;	
}
